package com.ibm.parse.controller;

import com.ibm.parse.service.NJBankParseService;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONString;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 手机银行词义解析controller
 * @author lisheng
 */
@SuppressWarnings("rawtypes")
@Controller
public class NJBankController {

	@Autowired
	private NJBankParseService nJBankParseService;
	@RequestMapping(value = { "/njbankAnalysis" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }, produces = { "text/html;charset=UTF-8" })
	@ResponseBody
	public String getProduct(HttpServletRequest request,HttpServletResponse response,String des) throws UnsupportedEncodingException {
		System.out.println(des);
		request.setCharacterEncoding("gbk");
		Map map = (Map) this.nJBankParseService.parseMenuKeyword(des);
		JSONArray json = JSONArray.fromObject(map);
		
		return json.toString().substring(1, json.toString().length()-1);
	}
	
	@RequestMapping(value = { "/updateMenuKeyword" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET }, produces = { "text/html;charset=UTF-8" })
	@ResponseBody
	public String updateMenuKeyword(Locale locale, Model model) {
		this.nJBankParseService.updateMenuKeyword();
		return "1";
	}

	@RequestMapping(value = { "/updateMenuIdentifier" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET }, produces = { "text/html;charset=UTF-8" })
	@ResponseBody
	public String updateMenuIdentifier(Locale locale, Model model) {
		this.nJBankParseService.updateMenuIdentifier();
		return "1";
	}
}